PreferenceWidget = new Object();

PreferenceWidget.init = function(saveCallback)
{
    // zebra transform
    var selections = '';
    selections += '#widget_preference_DIV_1 input[type="checkbox"], ';
    selections += '#widget_preference_DIV_1 input[type="radio"], ';
    selections += '#widget_preference_DIV_1 select';
    $.Zebra_TransForm($(selections));

    // bind save button
    var params = {ajaxUrl: PHP_PARAMS.perference_widget.ajaxUrl, saveCallback: saveCallback};
    $('#widget_preference_A_183').click(params, PreferenceWidget.onClickSavePrefernce);
}

PreferenceWidget.onClickSavePrefernce = function(event)
{
    var params = new Object();
    params.searchPurposeId = $('#widget_preference_UL_4 input[name=purpose_of_search]:checked').val();
    params.interestId = $('#widget_preference_UL_22 input[name=show_me]:checked').val();
    params.genderId = $('#widget_preference_UL_40 input[name=gender]:checked').val();
    params.ageFrom = $('#widget_preference_UL_40 select[name=age_from] option:selected').val();
    params.ageTo = $('#widget_preference_UL_40 select[name=age_to] option:selected').val();
    params.cityId = 23109;
    params.distance = $('#widget_preference_DIV_158 select[name=distance] option:selected').val();
    $.post(CONST.BASE_URL + '/' + event.data.ajaxUrl, params, function(json)
    {
        var data = JSON.parse(json);

        // callback
        var callback = event.data.saveCallback;
        if(callback)
        {
            callback(data);
        }
    });
}